#include <bits/stdc++.h>

using namespace std;
struct Big
{
    int d[1000];
    int len;
    Big()
    {
        memset(d,0,sizeof(d));
        len=0;
    }
};
Big str2BigNum(char s[])
{
    Big c;
    c.len=strlen(s);
    for (int i=0; i<c.len ; ++i )
    {
        c.d[i]=s[c.len-i-1]-'0';
    }
    return c;
}
Big addBigNum(Big a,Big b)
{
    Big c;
    int carry=0,temp;
    for (int i=0; i<a.len||i<b.len ; ++i )
    {
        temp=a.d[i]+b.d[i]+carry;
        c.d[c.len++]=temp%10;
        carry=temp/10;
    }
    while (carry!=0)
    {
        c.d[c.len++]=carry%10;
        carry/=10;
    }
    return c;
}
bool isPalindromicBigNumber(Big a)
{
    int mid=a.len/2;
    bool flag=true;
    for (int i=0; i<mid ; ++i )
    {
        if (a.d[i]!=a.d[a.len-i-1])
        {
            flag=false;
            break;
        }
    }
    return flag;
}
void printBigNum(Big a)
{
    for (int i=a.len-1;i>=0 ;--i )
    {
        printf("%d",a.d[i]);
    }
    putchar('\n');
}
int main_1024_2()
{
    char N[13]= {0};
    int K,steps=0;
    scanf("%s%d",N,&K);
    Big a=str2BigNum(N),b;
    while (steps<K)
    {
        if (isPalindromicBigNumber(a))
        {
            break;
        }
        else
        {
            b=a;
            reverse(a.d,a.d+a.len);
            a=addBigNum(a,b);
        }
        ++steps;
    }
    printBigNum(a);
    printf("%d",steps);
    return 0;
}
